<?php
class Model extends ObjectRelationalMapper {
	
	/**
	 * In order to behave like a normal class,
	 * Model keeps track of fields assigned at dynamically.
	 * @var array
	 */
	private $dynamicValues;
	
	public function __set($name, $value) {
		if($this->fieldExists($name)) {
			$this->setValue($name, $value);
		} else {
			if(!isset($this->dynamicValues))
				$this->dynamicValues = array();
			$this->dynamicValues[$name] = $value;
		}
	}
	
	public function __get($name) {
		if($this->fieldExists($name)) {
			return $this->getValue($name);
		} else {
			if(!isset($this->dynamicValues))
				$this->dynamicValues = array();
			if(isset($this->dynamicValues[$name]))
				return $this->dynamicValues[$name];
		}
	}
	
	public function __isset($name) {
		if($this->fieldExists($name)) {
			return $this->getValue($name);
		} else {
			return isset($this->dynamicValues[$name]);
		}
	}
	
	public function __unset($name) {
		if($this->fieldExists($name)) {
			$this->_unset($name);
		} else {
			unset($this->dynamicValues[$name]);
		}
	}
}
?>